﻿<cfscript>
/** 
* ORM CourseSign
* 
* @hint "Hibernate persistenter t_course_sign. 学院申请开课情况" 
* 
*/ 

component 
	displayname="public.service.orm.senate.CourseSign" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="CourseSign" 
	table="t_course_sign"
	{
	
	property type="string" name="CCID" column="csid" fieldtype="id" generator="assigned" hint="申请开课序号";

	property type="string" name="CourseName" column="course_name" hint="课程名称";
	property type="string" name="CourseEnglish" column="course_english" hint="课程英文名称";

	property type="numeric" name="Credit" column="course_credit" hint="学分";
	property type="numeric" name="Period" column="period" hint="总学时";
	property type="numeric" name="PeriodTheory" column="period_theory" hint="理论学时";
	property type="numeric" name="PeriodPractice" column="period_practice" hint="实践学时";
	property type="numeric" name="PeriodComputer" column="period_computer" hint="上机学时";
	property type="numeric" name="PeriodPerWeek" column="period_week" hint="排课周学时";

	property type="string" name="Intro" column="intro" hint="课程简介";
	property type="string" name="ReferenceBooks" column="reference_books" hint="参考书目";

	property type="string" name="MarkMode" column="mark_mode" hint="计分模式";
	property type="string" name="ResitPolicy" column="resit_policy" hint="补考安排规则";
	property type="string" name="SignStat" column="sign_stat" hint="开课审批状态";

	property name="Institute" fieldtype="many-to-one" fkcolumn="institute_id" cfc="Institute"  hint="任课单位";
	property name="Catalog" fieldtype="many-to-one" fkcolumn="cat_id" cfc="CourseCatalog"  hint="课程分类目录";

	/**
	* @hint "自定义主键规则"
	* 
	* @Institute "任课单位"
	*/
	public string function getNextID( required Institute ) output=false {
		
		var nextID = arguments.Institute.getInstituteID() & numberFormat(1, "0___");
		var checkArray = ORMExecuteQuery("select CCID from CourseSign 
											where CCID like :condition 
											order by CCID desc", { condition=arguments.Institute.getInstituteID() & "____" }, { maxResults=1 });
		
		/* 
			主键生成规则 VARCHAR(12)
			
			部门代码 + 4位为流水号
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.Institute.getInstituteID() & numberFormat((right(checkArray[1], 4) + 1), "0___");
			
		}

		return nextID;
		
	}

}

</cfscript>